
package fr.mehfile.api.update.settings;


import fr.mehfile.view.utils.Constants;
import fr.mehfile.view.utils.Utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class UpdateManagerSettings {
    private static final String TAG = "UpdateManagerSettings";

    private static final String PREF_FILENAME = "updatevalues";

    private static final String URL_SERVER_PREF = "urlserver";
    private static final String XML_VERSION_PREF = "xmlVersion";
    
    private SharedPreferences sharedPreferences;
    private Editor sharedPreferencesEditor;

    public UpdateManagerSettings(Context context) {
        sharedPreferences = context.getSharedPreferences(PREF_FILENAME, Context.MODE_PRIVATE);
        sharedPreferencesEditor = sharedPreferences.edit();
    }

    public boolean commit() {
        Utils.debugger.logDebug(TAG, " Settings Committed");
        return sharedPreferencesEditor.commit();
    }

    public void abordTransaction() {
        Utils.debugger.logDebug(TAG, " Settings Aborted");
        sharedPreferencesEditor = sharedPreferences.edit();
    }

    public String getUrlServer() {
        return sharedPreferences.getString(URL_SERVER_PREF, Constants.SERVER_URL);
    }

    public void setUrlServer(String newUrlServer) {
        sharedPreferencesEditor.putString(URL_SERVER_PREF, newUrlServer);
    }


    public int getXmlVersion() {
        return sharedPreferences.getInt(XML_VERSION_PREF, -1);
    }

    public void setXmlVersion(int id) {
        sharedPreferencesEditor.putInt(XML_VERSION_PREF, id);
    }
    
}
